require('../less/homePage.less') //引入css
document.ready(function () {
    // 判定用户是否登录
    if (!window.utils.ifLogin()) {
        window.location.href = './login.html';
    }
    window.utils.jumpPage('homePage');

    new Swiper('.swiper-container', {
        direction: 'horizontal', // 垂直切换选项
        autoplay: true, //自动播放
        loop: true, // 循环模式选项
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },
    })
    //获取所有的节点
    let rankCount = document.getElementById('rankCount') //今日排名
    let punchSum = document.getElementById('punchSum') //累计打卡
    let checkBtn = document.getElementById('checkBtn') //今日打卡
    let badge = document.getElementById('badge') //徽章
    let id = JSON.parse(window.localStorage.getItem('userData')).userId

    //获取数据
    function gethPage() {
        // ajax调用
        window.$http.get(`/headPageInfo?userId=${id}`, function (res) {
            if (res.status == 0) {
                render(res.data)
                console.log(res);
            }
        })
    }

    // 渲染数据
    function render(data) {
        rankCount.textContent = data.rank //今日排名
        badge.textContent = data.insigniaNum //徽章
        punchSum.textContent = data.punchIn //累计打卡
        checkBtn.textContent = data.isPunch == 'true' ? '今日已打卡' : '今日打卡';


    }
    gethPage()
    checkBtn.addEventListener('click', function () {
        window.$http.get(`/clockIn/?userId=${id}`, function (res) {
            console.log(res);
            if (res.status == 0) {
                checkBtn.innerHTML = '今日打卡'
            } else if (res.status == 1)[
                alert(res.msg)

            ]
        })

    })





})